-- Leviathan (c) v.v.balashoff
local Class = require('leviathan/Class')
local imagesList = require('images/list')

local ImagesManager = Class:derive('ImagesManager')

function ImagesManager:new()
    self.images = {}
end

function ImagesManager:getImageTexture(imgPath)
    local r = nil
    -- check images list
    local path = imagesList[imgPath]
    if not path then
        path = imgPath
    end
    -- get texture
    if not self.images[path] then
        local img = {}
        img.texture = love.graphics.newImage(path)
        if not img.texture then
            -- TODO переделать в ошибку?
            print('ERROR! Image not found: '..imgPath)
        end
        img.path = path
        img.imagedata = love.image.newImageData(img.path)
        img.w = img.texture:getWidth()
        img.h = img.texture:getHeight()
        -- adding to array
        self.images[path] = img
    end
    r = self.images[path]
    return r
end

return ImagesManager
